﻿class Particle extends MovieClip {
	public var vel:Object = new Object;
	public var gravity:Object = new Object;
	
	public var mass:Number = 10;
	public var friction:Number = 0.1;
	public var bounce:Number = 0.2;
	
	public var radius:Number = 7.5;
	
	public function init(m:Number, f:Number, b:Number):Void {
		vel = {x:0, y:0};
		gravity = {x:0.0, y:0.1};
		
		mass = m;
		friction = f;
		bounce = b;
		
		var a = _root.attachMovie("arrow", "arrow", 1, {_x:0, _y:0} );
		a.mc = this;
	}
	
	public function resolveCollision(v:Vector, p:Point):Void {
		
	}
	
	public function setVector(v:Vector):Void {
		if (v) {
			vel.x = v.dx;
			vel.y = v.dy;
		}
	}
	public function setVectBounce(v:Vector):Void {
		if (v) {
			vel.x = v.dx * (1 - bounce);
			vel.y = v.dy * (1 - bounce);
		}
	}
	
	//apply force to Particle
	public function force(f:Object):Void {
		vel.x += (f.x)/mass ;
		vel.y += (f.y)/mass ;
	}
	
	public function invis():Void {
		if (_alpha == 100) {
			_alpha = 20;
		} else {
			_alpha = 100;
		}
	}
	
	public function reverse():Void {
		vel.x *= -1;
		vel.y *= -1;
	}
	
	public function getVector():Vector {
		var v = new Vector( new Point(_x, _y), vel.x, vel.y );
		return v;
	}
	
	public function setVelocity(v:Vector):Void {
		if (v) {
			vel.x = v.dx;
			vel.y = v.dy;
		}
		//trace("setVector(): [" + v.dx + ", " + v.dy + "]");
	}
	
	public function onPress():Void {
		invis();
	}
}